<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>分配业务员</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="${pageContext.request.contextPath}/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
<link href="${pageContext.request.contextPath}/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
<link href="${pageContext.request.contextPath}/css/animate.min.css" rel="stylesheet">
<link href="${pageContext.request.contextPath}/css/style.min.css?v=4.1.0" rel="stylesheet">
<link href="${pageContext.request.contextPath}/jQuery-Validation/css/validationEngine.jquery.css" rel="stylesheet">
</head>
<body>
<div class="container" style="margin-top: 20px">
	<form class="form-horizontal" role="form" id="distributeSalesmanForm">
	     <div class="form-group">
	         <label class="col-sm-4 control-label">业务员:</label>
	         <div class="col-sm-4">
	             <select class="form-control validate[required]" name="workSalesman" id="workSalesman">
	                 <option value="">请选择</option>
	             </select>
	         </div>
	     </div>
	     <div class="form-group" style="margin-left: 100px;margin-top: 100px">
	         <div class="col-sm-6  control-label">
	             <button type="button" class="btn btn-default" onclick="closeForm();">关闭</button>
	             &nbsp;&nbsp;&nbsp;&nbsp;<button type="submit" class="btn btn-primary" id="save">确定</button>
	         </div>
	     </div>
	</form>
</div>
<script src="${pageContext.request.contextPath}/js/jquery.min.js?v=2.1.4"></script>
<script src="${pageContext.request.contextPath}/js/bootstrap.min.js?v=3.3.6"></script>
<script src="${pageContext.request.contextPath}/js/plugins/layer/layer.min.js"></script>
<script src="${pageContext.request.contextPath}/jQuery-Validation/js/jquery.validationEngine.js"></script>
<script src="${pageContext.request.contextPath}/jQuery-Validation/js/jquery.validationEngine-zh_CN.js"></script>
<script src="${pageContext.request.contextPath}/js/public/ttbj-core.js"></script>
<script type="text/javascript">
var orderId = $.getUrlParam("id");
$(function(){
	//ajax请求数据库获取业务员的信息
    $.ajax({
        url: "../user/getSalesmanIdNameCompany.htm",
        cache: false,
        type: "get",
        dataType: "json",
        success: function (result) {
            if (result.status == 0) {
            	console.log(result.data);
            	addOptions(result.data, "#workSalesman");
                return;
            }
        }
    });
	
  	//是否验证成功
    $('#distributeSalesmanForm').validationEngine('attach', {
        validationEventTrigger : 'blur',
        promptPosition: 'inline',
        scroll: false,
        focusFirstField : true,
        onValidationComplete : function (form, valid) {
            if (valid){
            	adddistributeSalesmanInfo();
            }
        }
    });
});


//增加预订单分配业务员信息
function adddistributeSalesmanInfo() {
    $.ajax({
        url: "../order/addedOrderWorkInfo.htm",
        cache: false,
        type: "post",
        dataType: "json",
        data: {"workOrder":orderId, "workSalesman": $("#workSalesman").val()},
        success: function (result) {
            if (result.status == 0) {
                parent.layer.msg(result.message, {icon: 1});
                parent.$salesmanOrderTable.bootstrapTable('refresh', {url: '../order/getAdvanceSalOrderInfoByPage.htm'});
                closeForm();
            } else {
                parent.layer.msg(result.message, {icon: 2});
                closeForm();
            }
        }
    });
}

//下拉列表  追加到option中
function addOptions(data, selectId){
	for(var i=0; i<data.length; i++){
		$(selectId).append('<option value="' + data[i].salesmanId + '">' + data[i].salesmanName + '</option>');
	}
}

//关闭窗口
function closeForm() {
    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
    parent.layer.close(index);
}

</script>
</body>
</html>